package com.bj58.data.emailreports.sends;

import java.util.Date;
import java.util.List;

import com.bj58.data.emailreports.controllers.BusiWeekReportController;
import com.bj58.data.emailreports.model.EmailReportUser;
import com.bj58.data.emailreports.utils.DateUtil;

/**
 * @author huangliang
 *
 */
public class BWRSend extends BaseSend{

	
	public static void main(String[] args) {
		BWRSend  fs = new BWRSend();
		BusiWeekReportController  wk = new BusiWeekReportController();
		try {
			//执行日期   
			String searchDate = DateUtil.getStringDate(new Date(),"yyyy-MM-dd");
			
			//发送类型   all:part1-3  / 1:part1 / 2:part2 / 3:part3
			String sendType = "all";
			
			if(null != args && args.length > 0){
				if(args.length != 2){
					System.out.println("params error ! ");
					System.exit(0);
				}
				
				if(args[0].contains("-")){
					searchDate = args[0].trim();
				}
				
				sendType = args[1].trim();
			}
			System.out.println(searchDate);
			System.out.println(sendType);
			
			
			
			String beginDate = DateUtil.getStringDate(DateUtil.getDateBefore(DateUtil.strToDate(searchDate, "yyyy-MM-dd"), 7),"yyyy-MM-dd");
			String endDate = DateUtil.getStringDate(DateUtil.getDateBefore(DateUtil.strToDate(searchDate, "yyyy-MM-dd"), 1),"yyyy-MM-dd");
			
			List<EmailReportUser> userListDayReport = fs.getUsersBySendType(36);//收件人
			
			
			String contextDayReport = "";

			//part 1
			if("all".equals(sendType.toLowerCase()) || "1".equals(sendType)){
				contextDayReport = wk.weekReportPartOne(endDate);
				if("".equals(contextDayReport)){
					fs.errorWarn("商业数据分析周报 from "+ beginDate + " to " + endDate + " part-1");
				}else{
					fs.ReportSend(userListDayReport, "商业数据分析周报 from "+ beginDate + " to " + endDate + " part-1(总体进度/简历进度/收入趋势 /会员收入趋势/流量趋势/页面类型流量趋势/精准各平台流量趋势/在线产品收入趋势-贴均效果)", contextDayReport, null);
				}
			}
		
			
			//part 2
			if("all".equals(sendType.toLowerCase()) || "2".equals(sendType)){
				contextDayReport = wk.weekReportPartTwo(endDate);
				if("".equals(contextDayReport)){
					fs.errorWarn("商业数据分析周报 from "+ beginDate + " to " + endDate + " part-2");
				}else{
					fs.ReportSend(userListDayReport, "商业数据分析周报 from "+ beginDate + " to " + endDate + "part-2(精准置顶参数变化/精准城市流量漏斗/精准类别流量漏斗/余额客户结构/余额客户结构 -客户分层/消耗周期)" , contextDayReport, null);
				}
			}
		
			//part 3
			if("all".equals(sendType.toLowerCase()) || "3".equals(sendType)){
				contextDayReport = wk.weekReportPartThree(endDate);
				if("".equals(contextDayReport)){
					fs.errorWarn("商业数据分析周报 from "+ beginDate + " to " + endDate + " part-3");
				}else{
					fs.ReportSend(userListDayReport, "商业数据分析周报 from "+ beginDate + " to " + endDate + "part-3(城市监控/类别监控/城市类别问题定位/重点城市类别监控)" , contextDayReport, null);
				}
			}
			
			//part 4
			if("all".equals(sendType.toLowerCase()) || "4".equals(sendType)){
				contextDayReport = wk.weekReportPartFour(endDate);
				if("".equals(contextDayReport)){
					fs.errorWarn("商业数据分析周报 from "+ beginDate + " to " + endDate + " part-4");
				}else{
					fs.ReportSend(userListDayReport, "商业数据分析周报 from "+ beginDate + " to " + endDate + "part-4(分平台收入变化/分来源收入变化/新增流失客户/余额指标)" , contextDayReport, null);
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
			fs.errorWarn("商业数据分析周报报错!");
		}finally{
			System.exit(0);
		}
	}
	
}
